﻿<template>
	<div class="omsPhone7Segment-container">
		<el-dialog v-model="state.isShowDialog" draggable width="769px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" size="default" label-width="80px" :rules="rules">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="手机号码" prop="phone7">
							<el-input :maxlength="7" v-model="state.ruleForm.phone7" placeholder="请输入手机号码前7位"
								class="w100" clearable :disabled="state.seg" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="省份" prop="province">
							<el-select :clearable='true' class='w100' v-model='state.ruleForm.province'
								placeholder='请选择' filterable>
								<el-option v-for='item in optionDict.provinceDict' :key='item.value' :label='item.label'
									:value='item.value' />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="城市" prop="city">
							<el-input v-model.trim="state.ruleForm.city" placeholder="请输入城市" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="运营商" prop="operatorPlatform">
							<!-- <el-input v-model="state.ruleForm." placeholder="请输入运营商" class="w100" clearable /> -->
							<el-select v-model.trim="state.ruleForm.operatorPlatform" placeholder="请选择" class="w100">
								<el-option v-for='item in optionDict.operatorPlatformDict' :key='item.value'
									:label='item.label' :value='item.value' />
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" size="default">取 消</el-button>
					<el-button type="primary" @click="submit" size="default">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="editOmsPhone7Segment">
import { reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import type { FormRules } from "element-plus";
import mittBus from '/@/utils/mitt';
import { optionDict } from '/@/const/dict';
import { Phone7Segment } from '/@/api/models';
import SysOmsPhone7SegmentApi from '/@/api/common/Phone7Segment';

// 定义变量内容
const props = defineProps({
	title: String,
});
const ruleFormRef = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {} as Phone7Segment,
	seg: false
});

// 删除非必填规则
const rules = ref<FormRules>({
	phone7: [{ required: true, message: '请输入手机号码前7位！', trigger: 'blur', },],
	province: [{ required: true, message: '请输入省份！', trigger: 'blur', },],
	city: [{ required: true, message: '请输入城市！', trigger: 'blur', },],
	operatorPlatform: [{ required: true, message: '请输入运营商 0:未知 1:移动 2:联通 3:电信 4:广电！', trigger: 'blur', },],
});

// 打开弹窗
const openDialog = (row: Phone7Segment, seg) => {
	state.seg = false;
	// console.log(seg == true);
	if (seg) state.seg = true;
	state.ruleForm = row;
	state.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	mittBus.emit('submitRefresh');
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean, fields?: any) => {
		if (valid) {
			let res;
			if (state.seg)
				res = await SysOmsPhone7SegmentApi().editPost(state.ruleForm);
			else
				res = await SysOmsPhone7SegmentApi().addPost(state.ruleForm);
			if (res.data.resCode != '0000')
				ElMessage.error(res.data.resMessage);
			else {
				ElMessage.success("操作成功");
				closeDialog();
			}
		} else {
			ElMessage({
				message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
				type: "error",
			});
		}
	});
};

// 导出对象 将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
